package arraylist;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test8 {

    public static void main(String[] args) {
        //8.sublist
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        list1.add(5);
        System.out.println(list1.subList(1,4));//左闭又开
        List<Integer> sublist1 = list1.subList(1,4);
        sublist1.set(2,100);
        System.out.println(list1);
        System.out.println(sublist1);
        //9.求元素个数
        System.out.println(list1.size());
        //10.遍历所有的元素
        //a .
        int i = 0;
        for (i = 0; i < list1.size(); i++){
            System.out.println(list1.get(i));
        }
        //b .
        for (Integer num:list1){
            System.out.println(num);
        }
        //c 迭代器
        Iterator<Integer> iterator = list1.listIterator();
        //通过 hasNext 判定是否遍历结束
        while (iterator.hasNext()){
            //通过 next 获取 list1 中的每个元素
            System.out.println(iterator.next());
        }
    }
}
